﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TiTi.tea.DAL;
using TiTi.tea.Model;

namespace TiTi.tea.BLL
{
    public  class DictInfoBLL
    {
        DictInfoDAL udal=new DictInfoDAL();

        public IEnumerable<DictInfo> Query(string DictName,out int Toatal, int PageSize,int PageIdex) 
        {
            var date = udal.GetAll();
            Toatal = date.Count();
            if (!string.IsNullOrEmpty(DictName)) 
            {
                date = date.Where(o => o.DictName.Contains(DictName));

            }
            return date.OrderBy(o => o.CreateTime).Skip(PageSize*(PageIdex-1)).Take(PageSize);
        }

        public DictInfo Get(int id) 
        {
            return udal.GetOne(o=>o.Id==id);
        }
        public bool Add(DictInfo entity) 
        {
        return udal.Add(entity);
        }
        public bool Update(DictInfo entity) 
        {
        return udal.Update(entity);
        }
        public bool Delete(int id) 
        {
        DictInfo dictInfo= new DictInfo();
            dictInfo.Id = id;
            udal._dbContext.Entry(dictInfo).State=System.Data.Entity.EntityState.Unchanged;
            dictInfo.IsDelete = 1;
            return udal.SaveChanges();
        }
    }
}
